package com.bawei.flume.interceptor;

import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;

import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;

    public class ETLInterceptor implements Interceptor{

        @Override
        public void initialize() {

        }

        @Override
        public Event intercept(Event event) {
            byte[] body=event.getBody();
            String log=new String(body, StandardCharsets.UTF_8);
            if(JSONUtils.isJSONValidator(log)){
                return event;
            }else{
                return null;
            }
        }

        @Override
        public List<Event> intercept(List<Event> list) {
            Iterator<Event> iterator=list.iterator();
            while (iterator.hasNext()){
                Event next=iterator.next();
                if(intercept(next)==null){
                    iterator.remove();
                }
            }
            return list;
        }

        public class Bulider implements Interceptor.Builder{
            @Override
            public void configure(Context context){

            }

            @Override
            public Interceptor build() {
                return new ETLInterceptor();
            }
        }
        @Override
        public void close() {

        }
    }












































